define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'butterfly/mark/index' + location.search,
                    add_url: 'butterfly/mark/add',
                    edit_url: 'butterfly/mark/edit',
                    del_url: 'butterfly/mark/del',
                    multi_url: 'butterfly/mark/multi',
                    import_url: 'butterfly/mark/import',
                    table: 'butterfly_mark',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'cn_name', title: __('Cn_name'), operate: 'LIKE'},
                        {field: 'thumb_image', title: __('Thumb_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'butterfly_id', title: __('Butterfly_id')},
                        {field: 'nav_id', title: __('Nav_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'lng', title: __('Lng'), operate: 'LIKE'},
                        {field: 'lat', title: __('Lat'), operate: 'LIKE'},
                        {field: 'province', title: __('Province'), operate: 'LIKE'},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status')},
                        {field: 'butterfly.id', title: __('Butterfly.id')},
                        {field: 'butterfly.name', title: __('Butterfly.name'), operate: 'LIKE'},
                        {field: 'butterfly.cn_name', title: __('Butterfly.cn_name'), operate: 'LIKE'},
                        {field: 'butterfly.thumb_image', title: __('Butterfly.thumb_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'butterfly.nav_id', title: __('Butterfly.nav_id')},
                        {field: 'butterfly.user_id', title: __('Butterfly.user_id')},
                        {field: 'butterfly.createtime', title: __('Butterfly.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'butterfly.updatetime', title: __('Butterfly.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'butterfly.weigh', title: __('Butterfly.weigh')},
                        {field: 'butterfly.status', title: __('Butterfly.status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
